package gpstools.track;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

abstract class AdditionalInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    private Map<String, Serializable> data;

    private Map<String, Serializable> data() {
        if (data == null) {
            data = new HashMap<String, Serializable>();
        }
        return data;
    }

    public Serializable set(String name, Serializable value) {
		if (!exists(name) && value == null)
			return null;
        return data().put(name, value);
    }

	private boolean exists(String name) {
		return data().get(name) != null;
	}

    /**
     * Generic method to get the attribute
     * 
     * @param name
     *            attribute name
     * @return value
     */
    public Serializable get(String name) {
        return data().get(name);
    }
    
	public String getString(String name) {
		Serializable value = get(name);
		return value != null ? value.toString() : null;
	}

}